import React, { Component } from 'react';
import Aheader from '../components/allpro/Aheader';
import Anav from '../components/allpro/Anav';
import Alist from '../components/allpro/Alist';
import { getSearch } from '../api/search'
import { getAllprolist } from '../api/allpro'

class AllPro extends Component {
    constructor(props) {
        super(props)
        this.state = {
            plist: [],
            id: '',
        }
    }


    async componentDidMount() {
        //三级分类商品
        if (this.props.location.state!=null) {
            let res1 = await getAllprolist({ id: this.props.location.state.id })
            // console.log(res1.data.list,'三级分类');
            this.setState({
                plist: res1.data.list
            })
        }

        //搜索关键字
        if (this.props.location.state!=null&&this.props.location.state.key!=undefined) {
            let res2 = await getSearch({ searchkey: this.props.location.state.key })
            // console.log(res2, '搜索');
            this.setState({
                plist: res2.data.list
            })
        }
    }

    render() {
        return (
            <div className='allpro'>
                <Aheader></Aheader>
                <Anav></Anav>
                <Alist plist={this.state.plist}></Alist>
            </div>
        );
    }
}

export default AllPro;